package com.neusoft.nepm.repository;

import com.neusoft.nepm.dto.MessageDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class MessageRepository {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public boolean checkUserExists(String telId) {
        String sql = "SELECT COUNT(*) FROM nep.supervisor WHERE tel_id = ?";
        int count = jdbcTemplate.queryForObject(sql, new Object[]{telId}, Integer.class);
        return count > 0;
    }

    public void saveMessage(MessageDto message) {
        String sql = "INSERT INTO nep.messages (tel_id, title, content, send_date, status) VALUES (?, ?, ?, ?, ?)";
        jdbcTemplate.update(sql, message.getTelId(), message.getTitle(), message.getContent(), message.getSendDate(), message.getStatus());
    }
}